<%--
  Created by IntelliJ IDEA.
  User: joker
  Date: 2023/5/17
  Time: 8:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>CoolMeeting会议管理系统管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/styles/common.css"/>
    <script src="${pageContext.request.contextPath}/js/node_modules/jquery/dist/jquery.js"></script>
</head>
<body>
<div class="page-header">
    <div class="header-banner">
        <img src="${pageContext.request.contextPath}/images/header.png" alt="CoolMeeting"/>
    </div>
    <div class="header-title">
        欢迎访问Cool-Meeting会议管理系统
    </div>
    <div class="header-quicklink">
        欢迎您，<strong>${accountName}</strong>
        <a href="adminChangePassword.do">[修改密码]</a>
    </div>
</div>
<div class="page-body">
    <div class="page-sidebar">
        <div class="sidebar-menugroup">
            <div class="sidebar-grouptitle">人员管理</div>
            <ul class="sidebar-menu">
                <li class="sidebar-menuitem"><a href="department.do">部门管理</a></li>
                <li class="sidebar-menuitem"><a href="register.do">员工注册</a></li>
                <li class="sidebar-menuitem">
                    <a href="employeeApprove.do?accountName=${accountName}&password=${emp.password}" >注册审批</a></li>
                <li class="sidebar-menuitem"><a href="search.do">搜索员工</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="page-content">
    <div class="content-nav">
        人员管理 > 搜索员工
    </div>
    <form action="search.do" method="post">
        <fieldset>
            <legend>搜索员工</legend>
            <table class="formtable">
                <tr>
                    <td>姓名：</td>
                    <td>
                        <input type="text" name="employeeName" id="employeeName" value="${nameLike}" maxlength="20"/>
                    </td>
                    <td>账号名：</td>
                    <td>
                        <input type="text" name="accountName" id="accountName" value="${accountLike}" maxlength="20"/>
                    </td>
                    <td>状态：</td>
                    <td>
                        <input type="radio" name="flag" value="1" ${flag==1?'checked':''} /><label>已批准</label>
                        <input type="radio" name="flag" value="0" ${flag==0?'checked':''} /><label>待审批</label>
                        <input type="radio" name="flag" value="-1" ${flag==-1?'checked':''} /><label>已关闭</label>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="command">
                        <input type="submit" class="clickbutton" value="查询" onclick="showSelectedRadio()"/>
                        <input type="reset" class="clickbutton" value="重置"/>
                    </td>
                </tr>
            </table>
        </fieldset>
    </form>
    <div>
        <h3 style="text-align:center;color:black">查询结果</h3>
        <div class="pager-header">
            <div class="header-info">
                共<span class="info-number">${empPageInfo.total}</span>条结果，
                分成<span class="info-number">${empPageInfo.pages}</span>页显示，
                当前第<span id="currentNum" class="info-number">${empPageInfo.pageNum}</span>页
            </div>
            <div class="header-nav">
                <input id="firstPageBtn" type="button" class="clickbutton" value="首页"/>

                <input id="prevPageBtn" type="button" class="clickbutton" value="上页"/>
                <input id="nextPageBtn" type="button" class="clickbutton" value="下页"/>
                <input id="lastPageBtn" type="button" class="clickbutton" value="末页"/>
                跳到第<input type="text" id="jumpNum" class="nav-number"/>页
                <input id="jumpBtn" type="button" class="clickbutton" value="跳转"/>
            </div>
        </div>
    </div>
    <table class="listtable">
        <tr class="listheader">
            <th>姓名</th>
            <th>账号名</th>
            <th>联系电话</th>
            <th>电子邮件</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${empPageInfo.list}" var="emp">
            <tr class="listbody">
                <td>${emp.employeeName}</td>
                <td>${emp.accountName}</td>
                <td>${emp.phone}</td>
                <td>${emp.email}</td>
                <td> <a id="${emp.empNo}" name="${emp.accountName}" class="clickbutton1">关闭账号</a></td>
            </tr>
        </c:forEach>
    </table>
</div>
</div>
<div class="page-footer">
    <hr/>
    更多问题，欢迎联系<a href="mailto:webmaster@eeg.com">管理员</a>
    <img src="${pageContext.request.contextPath}/images/footer.png" alt="CoolMeeting"/>
</div>
<script>

    let pageNum = ${empPageInfo.pageNum};
    let endNum = ${empPageInfo.pages};
    let nums = ${empPageInfo.total};
    // let jumpNum = $("#jumpNum")[0].value;
    console.log(pageNum);
    console.log(endNum);
    if (endNum==0){
        $("#currentNum").text(endNum);
    }
    //console.log(jumpNum);
    // if (pageNum==1){
    //     $("#prevPageBtn").attr("disabled",true);
    // }else {
    //     $("#prevPageBtn").attr("disabled",false);
    // }
    // if (pageNum==endNum){
    //     $("#nextPageBtn").attr("disabled",true);
    // }else{
    //     $("#nextPageBtn").attr("disabled",false);
    // }
    let $clickbutton1 = $(".clickbutton1");
    let len1 = $clickbutton1.length;
    for (let i = 0; i < len1; i++) {
        //console.log($clickbutton1[i]);
        $clickbutton1[i].onclick = ()=>{
            alert($clickbutton1[i].name+" 已关闭账户！！！");
            $.post("delete.do?empNo="+$clickbutton1[i].id,
                (data)=>{
                    //console.log(data);
                    if (data==1){
                        $clickbutton1[i].disabled = true;
                    }
                }
            )
        }
    }


    $("#firstPageBtn").click(()=>{
        if (pageNum==1||nums==0){
            alert("当前已经是首页！！！");
            return;
        }
        $.post("page.do?pageNum=1&employeeName=${nameLike}&accountName=${accountLike}&flag=${flag}",
           (data)=>{
               console.log(data);
               let $listbody = $(".listbody");
               $listbody.remove();
               let len = data.length;
               for (let i = 0; i < len; i++) {
                   let row = data[i];
                   let employeeName = row.employeeName;
                   let accountName = row.accountName;
                   let del = "<a id="+row.empNo+" name="+accountName+" class='clickbutton1'>关闭账号</a>";
                   let phone = row.phone;
                   let email = row.email;
                   let htmlTr = "<tr class='listbody'>"+
                       "<td>"+employeeName+"</td>"+
                       "<td>"+accountName+"</td>"+
                       "<td>"+phone+"</td>"+
                       "<td>"+email+"</td>"+
                       "<td>"+del+"</td>"
                        +"</tr>";
                   $(".listtable").append(htmlTr);
               }
           },
        )
        pageNum = 1;
        $("#currentNum").text(pageNum);
    });

    $("#prevPageBtn").click(()=>{
        if (pageNum==1||nums==0){
            alert("当前已经是首页,没有上一页！！！");
            return;
        }
        $.post("page.do?pageNum="+(pageNum-1)+"&employeeName=${nameLike}&accountName=${accountLike}&flag=${flag}",
            (data)=>{
                console.log(data);
                let $listbody = $(".listbody");
                $listbody.remove();
                let len = data.length;
                for (let i = 0; i < len; i++) {
                    let row = data[i];
                    let employeeName = row.employeeName;
                    let accountName = row.accountName;
                    let del = "<a id="+row.empNo+" name="+accountName+" class='clickbutton1'>关闭账号</a>";
                    let phone = row.phone;
                    let email = row.email;
                    let htmlTr = "<tr class='listbody'>"+
                        "<td>"+employeeName+"</td>"+
                        "<td>"+accountName+"</td>"+
                        "<td>"+phone+"</td>"+
                        "<td>"+email+"</td>"+
                        "<td>"+del+"</td>"
                        +"</tr>";
                    $(".listtable").append(htmlTr);
                }
            }
        )
        pageNum = pageNum -1;
        $("#currentNum").text(pageNum);
    });

    $("#nextPageBtn").click(()=>{
        if (pageNum==endNum||nums==0){
            alert("当前已经是末页,没有下一页！！！");
            return;
        }
        $.post("page.do?pageNum="+(pageNum+1)+"&employeeName=${nameLike}&accountName=${accountLike}&flag=${flag}",
            (data)=>{
                console.log(data);
                let $listbody = $(".listbody");
                $listbody.remove();
                let len = data.length;
                for (let i = 0; i < len; i++) {
                    let row = data[i];
                    let employeeName = row.employeeName;
                    let accountName = row.accountName;
                    let phone = row.phone;
                    let email = row.email;
                    let del = "<a id="+row.empNo+" name="+accountName+" class='clickbutton1'>关闭账号</a>";
                    let htmlTr = "<tr class='listbody'>"+
                        "<td>"+employeeName+"</td>"+
                        "<td>"+accountName+"</td>"+
                        "<td>"+phone+"</td>"+
                        "<td>"+email+"</td>"+
                        "<td>"+del+"</td>"
                        +"</tr>";
                    $(".listtable").append(htmlTr);
                }
            }
        )
        pageNum = pageNum + 1;
        $("#currentNum").text(pageNum);
    });

    $("#lastPageBtn").click(()=>{
        if (pageNum==endNum||nums==0){
            alert("当前已经是末页！！！");
            return;
        }
        $.post("page.do?pageNum="+endNum+"&employeeName=${nameLike}&accountName=${accountLike}&flag=${flag}",
            (data)=>{
                console.log(data);
                let $listbody = $(".listbody");
                $listbody.remove();
                let len = data.length;
                for (let i = 0; i < len; i++) {
                    let row = data[i];
                    let employeeName = row.employeeName;
                    let accountName = row.accountName;
                    let phone = row.phone;
                    let email = row.email;
                    let del = "<a id="+row.empNo+" name="+accountName+" class='clickbutton1'>关闭账号</a>";
                    let htmlTr = "<tr class='listbody'>"+
                        "<td>"+employeeName+"</td>"+
                        "<td>"+accountName+"</td>"+
                        "<td>"+phone+"</td>"+
                        "<td>"+email+"</td>"+
                        "<td>"+del+"</td>"
                        +"</tr>";
                    $(".listtable").append(htmlTr);
                }
            }
        )
        pageNum = endNum;
        $("#currentNum").text(pageNum);
    });

    $("#jumpBtn").click(()=>{
        if (nums==0){
            alert("当前没有查询到数据！！！");
            return;
        }
        if ($("#jumpNum")[0].value>endNum){
            alert("您输入的页码不正确！！！");
            return;
        }
        $.post("page.do?pageNum="+$("#jumpNum")[0].value+"&employeeName=${nameLike}&accountName=${accountLike}&flag=${flag}",
            (data)=>{
                console.log(data);
                let $listbody = $(".listbody");
                $listbody.remove();
                let len = data.length;
                for (let i = 0; i < len; i++) {
                    let row = data[i];
                    let employeeName = row.employeeName;
                    let accountName = row.accountName;
                    let phone = row.phone;
                    let email = row.email;
                    let del = "<a id="+row.empNo+" name="+accountName+" class='clickbutton1'>关闭账号</a>";
                    let htmlTr = "<tr class='listbody'>"+
                        "<td>"+employeeName+"</td>"+
                        "<td>"+accountName+"</td>"+
                        "<td>"+phone+"</td>"+
                        "<td>"+email+"</td>"+
                        "<td>"+del+"</td>"
                        +"</tr>";
                    $(".listtable").append(htmlTr);
                }
            }
        )
        pageNum = $("#jumpNum")[0].value;
        $("#currentNum").text(pageNum);
    });


</script>
</body>
</html>
